/**
 * Created by Administrator on 2017/9/26.
 */


/**
 * 将一个数组根据某个条数规则分成多个数组
 * */
Handlebars.registerHelper('cateList',function (value) {

    var valLen = value.length;
    var pageLen = 8;
    var result = [];
    for (var i = 0; i < valLen; i += pageLen){
        result.push(value.slice(i,i+pageLen));
    }
    return result;

});

//判断value的状态，渲染不同的数据
Handlebars.registerHelper('valueCompare', function(left, operator, right, options) {
    if (arguments.length < 3) {
        throw new Error('Handlerbars Helper "compare" needs 2 parameters');
    }
    var operators = {
        '==':     function(l, r) {return l == r; },
        '===':    function(l, r) {return l === r; },
        '!=':     function(l, r) {return l != r; },
        '!==':    function(l, r) {return l !== r; },
        '<':      function(l, r) {return l < r; },
        '>':      function(l, r) {return l > r; },
        '<=':     function(l, r) {return l <= r; },
        '>=':     function(l, r) {return l >= r; },
        'typeof': function(l, r) {return typeof l == r;
        }
    };

    if (!operators[operator]) {
        throw new Error('Handlerbars Helper "compare" doesn\'t know the operator ' + operator);
    }

    var result = operators[operator](left, right);

    if (result) {
        return options.fn(this);
    } else {
        return options.inverse(this);
    }
});
